<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加用户</title>


    <%include ../../common.ejs%>
    <script type="text/javascript" src="../../javascripts/bootstrap-datetimepicker.js"></script>
    <script type="text/javascript" src="../../javascripts/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript" src="../../javascripts/bootstrap-datetimepicker.zh-CN.js"></script>
    <script type="text/javascript">
        $(function () {
            $('.form_datetime').datetimepicker({
                format: 'yyyy-mm-dd',
                language: 'zh-CN',
                minView: "month",
                autoclose: true
            });
        })
        var checkEmail=function(){
            if ($("#Email").val() == "") {
                $("#msg3").empty();
                return false;
            }
            else {
                var email = $("#Email").val();
                var tagEmail = !!email.match(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/);
                if (tagEmail == false) {
                    //  $("#msg3").html("<img src='/images/icons/failure.png' style='height: 25px;width: 25px;'>");
                    alert("邮箱格式错误");
                    return false;
                }
            }
        }

        var checkTel = function () {
            if ($("#tel").val() == "") {
                //   $("#msg2").empty();
                alert("手机号码不能为空");
                return false;
            }
            var tel = $("#tel").val(); //获取手机号
            var telReg = !!tel.match(/^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/);
            //如果手机号码不能通过验证
            if (telReg == false) {
                alert("手机号码格式错误");
                return false;
            } else {
                var tag=true;
                $.ajax({
                    type:'post',
                    async:false,//同步提交
                    url: "/admin/peopleManagement/checkTelExist",
                    data: {
                        param: tel,
                    },
                    success: function (e) {
                        if (e.code == 200) {
                            tag=false;
                        }
                    }
                });
                if(tag==false){
                    alert("手机号码已被使用");
                    return false;
                }
            }
        }
        var checkAll = function () {
            if (checkTel() == false) {
                return false;
            }
            if (checkEmail()==false){
                return false;
            }
        }
        function submitForm() {
            if (checkAll() == false) {
                return false;
            }
        }
    </script>
</head>
<body>
<div id="top">
    <% include ../top.ejs%>
</div>
<div class="container-fluid" style="margin-top: 20px;">
    <div class="row">
        <div class="col-md-1">
        </div>
        <div id="left" class="col-md-2">
            <% include ../left.ejs%>
        </div>
        <div class="col-md-8 bodyDiv" id="right">

            <div class="row">
                <div class="col-md-6" >
                        <span class="headTitle">添加用户</span>
                </div>
            </div>

            <div class="row">
                <div class="form-group"
                     style="height: 300px;">
                    <form action="/admin/peopleManagement/addUser" method="post" onsubmit="return checkAll()">
                        <div class="row" style="padding-top: 50px;">

                            <div class="col-md-3">
                                <span class="pull-right" style="font-size: 20px;">用户姓名:</span>
                            </div>
                            <div class="col-md-3">
                                <input type="text" name="name" class="form-control" placeholder="必填" required
                                       oninvalid="setCustomValidity('请填写用户姓名');" oninput="setCustomValidity('');">
                            </div>
                            <div class="col-md-1">
                                <span class="pull-right" style="font-size: 20px;">性别:</span>
                            </div>
                            <div class="col-md-2">
                                <label>
                                    <input type="radio" name="sex" value="M" checked>
                                    男
                                </label>
                                &nbsp;&nbsp;&nbsp;
                                <label>
                                    <input type="radio" name="sex" value="F" checked>
                                    女
                                </label>
                            </div>
                        </div>

                        <div class="row" style="padding-top: 30px;">
                            <div class="col-md-3">
                                <span class="pull-right" style="font-size: 20px;">手机号码:</span>
                            </div>
                            <div class="col-md-3">
                                <input type="text" name="tel"  id="tel" class="form-control" placeholder="此项将为帐号" required
                                       oninvalid="setCustomValidity('请填写手机号码');" oninput="setCustomValidity('');">
                            </div>

                            <div class="col-md-1">
                                <span class="pull-right" style="font-size: 20px;">生日:</span>
                            </div>
                            <div class="col-md-3">
                                <!--<input type="text" class="form-control" placeholder="可选">-->
                                <input size="16" type="text" name="birthday" readonly
                                       class="form-control form_datetime">
                            </div>
                        </div>

                        <div class="row" style="padding-top: 30px;">
                            <div class="col-md-2">
                            </div>
                            <div class="col-md-1">
                                <span style="font-size: 20px;">邮箱:</span>
                            </div>
                            <div class="col-md-3">
                                <input type="text" name="email" id="Email" id="email" onblur="checkEmail()"  class="form-control" placeholder="可选">
                            </div>
                        </div>

                        <div class="row" style="padding-top: 30px;">
                            <div class="col-md-3">
                                <span class="pull-right" style="font-size: 20px;">联系地址:</span>
                            </div>
                            <div class="col-md-8">
                                <input type="text" name="address" class="form-control" placeholder="可选">
                            </div>
                        </div>

                        <div class="row" style="padding-top: 30px;">
                            <div class="col-md-3"></div>
                            <div class="col-md-3" style="text-align: center;">
                                <button type="submit" style="width: 180px;" class="btn btn-default" >
                                    添加
                                </button>

                            </div>
                        </div>
                    </form>

                </div>
                <!--内容-->
            </div>
            <div class="col-md-1"> </div>
        </div>
    </div>
</div>
</body>
</html>